package com.power.controller;

import com.alibaba.fastjson.JSON;
import com.power.ov.ResultData;
import com.power.ov.ResultDataTable;
import com.power.service.TowerService;
import com.power.service.impl.TowerServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;

/**
 * Created with IntelliJ IDEA.
 * User: 李辽
 * Date: 2020/10/07 13:55
 * Description:
 * Version: V1.0
 */
@WebServlet("/modifiesTowerStatus.do")
public class ModifiesTowerStatus extends HttpServlet {
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        int towper_id = Integer.parseInt(request.getParameter("towper_id"));
        String state_name = request.getParameter("state_name");
        TowerService towerService = new TowerServiceImpl();
        response.setContentType("application/json;charset=utf-8");
        ResultDataTable resultData = new ResultDataTable();

        int result = 0;
        try {
            result = towerService.ModifiesTowerStatus(towper_id,state_name);
            if (result>0){
                resultData.setCode(200);
                resultData.setMessage("更改成功。。。。");
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
        response.getWriter().write(JSON.toJSONString(resultData));
        response.getWriter().flush();
        response.getWriter().close();
    }
}
